package com.zzyl.nursing.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.mapper.MemberReservationMapper;
import com.zzyl.nursing.service.MemberReservationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class MemberReservationServiceImpl implements MemberReservationService {

    @Autowired
    private MemberReservationMapper memberReservationMapper;

    @Override
    public boolean createReservation(Reservation reservation) {
        try {
            reservation.setCreateTime(LocalDateTime.now());
            reservation.setStatus(0); // 默认设置为待报道状态
            memberReservationMapper.insertReservation(reservation);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public PageInfo<Reservation> getReservations(int pageNum, int pageSize,  Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        List<Reservation> reservations = memberReservationMapper.selectReservations( status);
        return new PageInfo<>(reservations);
    }
//    @Override
//    public long getCancelledCount() {
//        LocalDateTime now = LocalDateTime.now();
//        LocalDateTime startTime = now.toLocalDate().atStartOfDay();
//        LocalDateTime endTime = startTime.plusDays(1);
//
//        return memberReservationMapper.getCancelledCount(startTime, endTime);
//    }
}
